package com.aim.util;

import org.apache.commons.math3.distribution.BetaDistribution;

/**
 * Created with IntelliJ IDEA.
 * User: User
 * Date: 4/29/14
 * Time: 10:52 PM
 * To change this template use File | Settings | File Templates.
 */
public class BetaGenerator implements TimeGenerator {

    private BetaDistribution betaDistribution;
    public final long range;

    public BetaGenerator(double a, double b, long range) {
        betaDistribution = new BetaDistribution(a,b);
        this.range = range;
    }

    @Override
    public long nextTime() {
        return (long) (betaDistribution.sample()*range);
    }

    public double[] createDistribution(int numOfBuckets, int numOfSamples){
        Histogram histogram = new Histogram(0,range,numOfBuckets);
        for (int i = 0; i < numOfSamples; i++) {
            histogram.addValue(nextTime());
        }
        return histogram.getBuckets();
    }
}
